home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 3 / Amiga Format CD03 (1996-07-04)(Future Publishing)(GB)(Track 1 of 6)[!][issue 1996-08].iso / comms / netsoftware / archie38_1.lha / archie-1.4 / atalloc.c < prev    next >
C/C++ Source or Header  |  1995-01-05  |  2KB  |  102 lines

  1. /*
  2.  * Copyright (c) 1989, 1990 by the University of Washington
  3.  *
  4.  * For copying and distribution information, please see the file
  5.  * <copyright.h>.
  6.  */
  7. /* Amiga port by Tomas Willis (tomas@cae.wisc.edu) January 1995 */
  8.  
  9. #include <stdio.h>
  10.  
  11. #include "pfs.h"
  12. #include "pmachine.h" /* for correct definition of ZERO */
  13.  
  14. static PATTRIB    lfree = NULL;
  15. int        pattrib_count = 0;
  16. int        pattrib_max = 0;
  17. // protos
  18. void atlfree( PATTRIB at);
  19. PATTRIB atalloc(void);
  20. void atfree(PATTRIB at);
  21. // extern
  22. extern void vlfree(VLINK vl); //vlalloc.c
  23. extern void stfree(char *st); //stcopy.c
  24. extern int vl_insert(VLINK vl, PVDIR vd,int allow_conflict);
  25.  
  26. /*
  27.  * atalloc - allocate and initialize vlink structure
  28.  *
  29.  *    ATALLOC returns a pointer to an initialized structure of type
  30.  *    PATTRIB.  If it is unable to allocate such a structure, it
  31.  *    returns NULL.
  32.  */
  33. PATTRIB
  34. atalloc(void)
  35.     {
  36.     PATTRIB    at;
  37.     if(lfree) {
  38.         at = lfree;
  39.         lfree = lfree->next;
  40.     }
  41.     else {
  42.         at = (PATTRIB) malloc(sizeof(PATTRIB_ST));
  43.         if (!at) return(NULL);
  44.         pattrib_max++;
  45.     }
  46.  
  47.     pattrib_count++;
  48.  
  49.     ZERO(at);
  50.     /* Initialize and fill in default values; all items are
  51.        0 [or NULL] save precedence */
  52.     at->precedence = ATR_PREC_OBJECT;
  53.  
  54.     return(at);
  55.     }
  56.  
  57. /*
  58.  * atfree - free a PATTRIB structure
  59.  *
  60.  *    ATFREE takes a pointer to a PATTRRIB structure and adds it to
  61.  *    the free list for later reuse.
  62.  */
  63. void
  64. atfree(PATTRIB at)
  65. //    PATTRIB    at;
  66.     {
  67.     if(at->aname) stfree(at->aname);
  68.  
  69.     if((strcmp(at->avtype,"ASCII") == 0) && at->value.ascii) 
  70.         stfree(at->value.ascii);
  71.     if((strcmp(at->avtype,"LINK") == 0) && at->value.link) 
  72.         vlfree(at->value.link);
  73.     
  74.     if(at->avtype) stfree(at->avtype);
  75.  
  76.     at->next = lfree;
  77.     at->previous = NULL;
  78.     lfree = at;
  79.     pattrib_count--;
  80.     }
  81.  
  82. /*
  83.  * atlfree - free a PATTRIB structure
  84.  *
  85.  *    ATLFREE takes a pointer to a PATTRIB structure frees it and any linked
  86.  *    PATTRIB structures.  It is used to free an entrie list of PATTRIB
  87.  *    structures.
  88.  */
  89. void
  90. atlfree( PATTRIB at)
  91. //    PATTRIB    at;
  92.     {
  93.     PATTRIB    nxt;
  94.  
  95.     while(at != NULL) {
  96.         nxt = at->next;
  97.         atfree(at);
  98.         at = nxt;
  99.     }
  100.     }
  101.  
  102.